﻿using Urho;
using Urho.Gui;

namespace E3Dcontrol
{
    /// <summary>
    /// 3D应用接口类。实现对实体，摄像机，光线，输入的管理
    /// </summary>
    public class E3AppForUrho : Application
    {
        private Node EntityNode;
        private Camera camera;
        private Octree octree;



        public E3AppForUrho(ApplicationOptions options = null) : base(options) { }

        protected override void Start()
        {
            base.Start();

            // 3D scene with Octree
            var scene = new Scene(Context);
            octree = scene.CreateComponent<Octree>();

            // Camera
            var cameraNode = scene.CreateChild(name: "camera");
            cameraNode.Position = new Vector3(10, 14, 10);
            cameraNode.Rotation = new Quaternion(-0.121f, 0.878f, -0.305f, -0.35f);
            camera = cameraNode.CreateComponent<Camera>();

            // Light
            Node lightNode = cameraNode.CreateChild(name: "light");
            var light = lightNode.CreateComponent<Light>();
            light.LightType = LightType.Point;
            light.Range = 100;
            light.Brightness = 1.3f;

            // Viewport
            var viewport = new Viewport(Context, scene, camera, null);
            Renderer.SetViewport(0, viewport);
            viewport.SetClearColor(new Color(0.4f, 0.4f, 0.4f));

            EntityNode = scene.CreateChild();

            var baseNode = EntityNode.CreateChild().CreateChild();
            var plane = baseNode.CreateComponent<StaticModel>();
            plane.Model = ResourceCache.GetModel("Models/Plane.mdl");


        }
    }
}
